本地nginx 配置https访问产线api
安装nginx
1 2
| $ brew search nginx $ brew install nginx
|
自签证书
1 2 3 4 5 6 7 8 9 10 11
| # 其中,证书,不设置任何密码,便于nginx使用 openssl genrsa -des3 -passout pass:x -out http-ssl.pass.key 2048
openssl rsa -passin pass:x -in http-ssl.pass.key -out http-ssl.key
rm http-ssl.pass.key
openssl req -new -key http-ssl.key -out http-ssl.csr
openssl x509 -req -days 365 -in http-ssl.csr -signkey http-ssl.key -out http-ssl.crt
|
- 推荐命令写入sh脚本
本地host配置
nginx.conf配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| server { listen 443 ssl; server_name *.test.com api.test.com localhost; client_body_buffer_size 4k; client_max_body_size 4M; client_header_buffer_size 1k; large_client_header_buffers 4 1k; ssl_certificate ./ssl/http-ssl.crt; ssl_certificate_key ./ssl/http-ssl.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on;
location / { root /usr/share/nginx/html; index index.html index.htm; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8090; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
|
启动nginx
docker nginx配置
自签证书
本地host修改
nginx安装
nginx 配置
nginx 启动
1 2 3 4 5 6 7 8 9 10 11
| $ docker run \ --name my-nginx \ --rm \ -d -p 8090:80 \ -v $PWD/html:/usr/share/nginx/html \ -v $PWD/ssl:/etc/nginx/ssl \ -v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro \ -v $PWD/conf.d:/etc/nginx/conf.d \ -v $PWD/logs:/var/log/nginx \ nginx
|
- 可以将上述命令放入sh脚本中
1 2 3 4 5
| #!/bin/bash
docker stop my-nginx
.....
|
本文作者:前端analysis
版权声明: 本文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏